<?php
//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//
// DLMan by Shedd Technologies International		  				//
// http://www.dlman.com | info@dlman.com							//
// Copyright 2003 by STI, All rights reserved.						//
// ---------------------------------------------------------------- //
// Usage of this software is governed by the terms of GPL. 	    	//
//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//

require("cvar.php");
if($stage=="3"){
/*
Connect to the database and write the tables.
*/
	//load database connection information
	require($file);
	//mysql connection should have been created
	$sqlcode=array();
	//Load SQL
	if(file_exists("sql.txt")){
		$file = file("sql.txt");//read in entire file to an array
		foreach($file as $line){
			$line=trim($line);
			array_push($sqlcode, $line);
		}
		process($sqlcode,$mysql,$ver);
		$sqlcode=array();
		//usertable setup
		if(file_exists("fsql.txt")){
			if($comsetup=="no"){
				$file = file("fsql.txt");//read in entire file to an array
				foreach($file as $line){
					$line=trim($line);
					array_push($sqlcode, $line);
				}
			}
		}//end usertable
		process($sqlcode,$mysql,$ver);
		$sqlcode=array();
		//update install
		if(file_exists("usql.txt")){
				$file = file("usql.txt");//read in entire file to an array
				foreach($file as $line){
					$line=trim($line);
					array_push($sqlcode, $line);
				}
		}//end update install
		process($sqlcode,$mysql,$ver);
	}
	
	if($err!=true){
		//show configuration screen
		confirmation_screen($config,$comsetup);
	}
}//end stage 3
//--------------------------------------------------------------------
function confirmation_screen($config,$comsetup){
	print sheaderi();
?>
	<P align=center><FONT face=Verdana size=4>DLMan&nbsp;<?php print $ver; ?></FONT><BR><FONT face=Verdana>Installation &amp; Setup</FONT></P>
	<P>
	<HR width="90%" color=black SIZE=1>
	<P></P>
	<P align=left><FONT face=Verdana>The proper tables have been successfully written to your database.&nbsp; Now, please 
	fill out the below table with the indicated information so that Setup can complete the database changes.  These settings can be changed from within the Administration Area at any time.
	</FONT></P>
	<?php
	config_table($config,$comsetup);
	?>
	<P><FONT face=Verdana>Once you have completed this step, please click 
	Continue to have Setup make the neccessary additions to your 
	database.</FONT></P>
	<HR width="90%" color=black SIZE=1>
<?php
	print footer();
}//end function
function config_table($config,$comsetup){
	global $mysql,$comsetup;
	$sql="SELECT * FROM ".$mysql['pre']."settings";
	$result=mysql_query($sql);
	$setting=mysql_fetch_array($result);
?>
		<form action="setup_5.php" method="post">
		<table width="550" align="center" cellspacing="0" cellpadding="2" border="0">
		<tr>
		    <td colspan="2" bgcolor="#b7b7b7"><b>System Settings</b></td>
		</tr>
		<tr><td colspan="2" bgcolor="black"></td></tr>
		<tr>
		    <td bgcolor="#efefef">
		      <P align=right>System Title&nbsp;</P></td>
		    <td>&nbsp;<input type="text" name="title1" size="45" value="<?php echo $setting["title"]; ?>"></td>
		</tr>
		<tr>
		    <td bgcolor="#efefef">&nbsp;</td>
		    <td>&nbsp;</td>
		</tr>
		<tr>
		    <td bgcolor="#efefef">
		      <P align=right>URL to DLMan<br>(USE trailing slash)&nbsp;</P></td>
		    <td>&nbsp;<input type="text" name="scripturla" size="45" value="<?php echo $setting["script_url"]; ?>"></td>
		</tr>
		<tr>
		    <td bgcolor="#efefef">&nbsp;</td>
		    <td>&nbsp;</td>
		</tr>
		<tr>
		    <td bgcolor="#efefef">
		      <P align=right>Integrated Comunity URL (USE trailing slash)&nbsp;</P></td>
		    <td>&nbsp;<input type="text" name="forum_url1" size="45" value="<?php echo $setting["forum_url"]; ?>"></td>
		</tr>
		<tr>
		    <td bgcolor="#efefef">&nbsp;</td>
		    <td>&nbsp;</td>
		</tr>
		<tr>
		    <td bgcolor="#efefef">
		      <P align=right>Integrated Comunity Name&nbsp;</P></td>
		    <td>&nbsp;<input type="text" name="forum_title1" size="45" value="<?php echo $setting["forum_title"]; ?>"></td>
		</tr>
		<tr>
		    <td bgcolor="#efefef">&nbsp;</td>
		    <td>&nbsp;</td>
		</tr>
		<tr>
		    <td bgcolor="#efefef">
		      <P align=right>Integrated Registration Page (ex. register.php, based off of the comunity URL above)&nbsp;</P></td>
		    <td>&nbsp;<input type="text" name="forum_register1" size="45" value="<?php echo $setting["forum_register"]; ?>"></td>
		</tr>
		<tr>
		    <td bgcolor="#efefef">&nbsp;</td>
		    <td>&nbsp;</td>
		</tr>
		<tr>
		    <td bgcolor="#efefef">
		      <P align=right>Maximum File Size&nbsp;</P></td>
		    <td>&nbsp;<input type="text" name="max_file_size1" size="45" value="<?php echo $setting["max_file_size"]; ?>">&nbsp;bytes</td>
		</tr>
		<tr>
		    <td bgcolor="#efefef">&nbsp;</td>
		    <td>&nbsp;</td>
		</tr>
		<tr>
		    <td bgcolor="#efefef">
		      <P align=right>Sales Department Email Address&nbsp;</P></td>
		    <td>&nbsp;<input type="text" name="sales_address1" size="45" value="<?php echo $setting["sales_address"]; ?>"></td>
		</tr>
		<tr>
		    <td bgcolor="#efefef">&nbsp;</td>
		    <td>&nbsp;</td>
		</tr>
		<?php
			$cols=65;
			$rows=7;
		?>
		<tr>
		    <td bgcolor="#efefef">
		      <P align=right>Successful Payment Validation Email Message&nbsp;</P></td>
		    <td>&nbsp;<textarea cols="<?php print $cols; ?>" rows="<?php print $rows; ?>" class="prefinput" name="validation_go1"><?php echo $setting["validation_go"]; ?></textarea></td>
		</tr>
		<tr>
		    <td bgcolor="#efefef">&nbsp;</td>
		    <td>&nbsp;</td>
		</tr>
		<tr>
		    <td bgcolor="#efefef">
		      <P align=right>Delayed Payment Validation Email Message&nbsp;</P></td>
		    <td>&nbsp;<textarea cols="<?php print $cols; ?>" rows="<?php print $rows; ?>" class="prefinput"  name="validation_delay1"><?php echo $setting["validation_delay"]; ?></textarea></td>
		</tr>
		<tr>
		    <td bgcolor="#efefef">&nbsp;</td>
		    <td>&nbsp;</td>
		</tr>
		<tr>
		    <td bgcolor="#efefef">
		      <P align=right>Password Change Email Message&nbsp;</P></td>
		    <td>&nbsp;<textarea cols="<?php print $cols; ?>" rows="<?php print $rows; ?>" class="prefinput"  name="mail_passchg1"><?php echo $setting["mail_passchg"]; ?></textarea></td>
		</tr>
		<tr>
		    <td bgcolor="#efefef">&nbsp;</td>
		    <td>&nbsp;</td>
		</tr>
		<tr>
		    <td bgcolor="#efefef">
		      <P align=right>Lost Password Email Message&nbsp;</P></td>
		    <td>&nbsp;<textarea cols="<?php print $cols; ?>" rows="<?php print $rows; ?>" class="prefinput"  name="mail_lostpass1"><?php echo $setting["mail_lostpass"]; ?></textarea></td>
		</tr>
		<tr>
		    <td bgcolor="#efefef">&nbsp;</td>
		    <td>&nbsp;</td>
		</tr>
		<tr><td colspan="2" bgcolor="black"></td></tr>
		<tr>
		    <td colspan="2" bgcolor="#b7b7b7">
		      <P align=center><input class="but" type="submit" value="Edit Settings" class="button"></P></td>
		</tr>
		</table>
		<input type="hidden" name="stage" value="4">
		<input type="hidden" name="comsetup" value="<?php print $comsetup; ?>">
		
	</form>
<?php
}//end function
//--------------------------------------------------------------------
function process($sqlcode,$mysql,$ver){
	$err=false;
	foreach($sqlcode as $sql){
		/*
		Codes used in database definition file:
			[%PRE%] for DLMan Table Prefix
			[%FPRE%] for Community Table Prefix
		*/
		$sql=str_replace("[%PRE%]",$mysql['pre'],$sql);
		$sql=str_replace("[%FPRE%]",$mysql['fpre'],$sql);
		$sql=str_replace("[%VER%]",$ver,$sql);
		
		$result=mysql_query($sql);
		if(!$result){
			die("Problem loading tables!<br><br><pre>$sql</pre><br><br>".mysql_error());
			$err=true;
		}
	}
	return true;
}
?>
